import * as Cesium from 'cesium'

let typeNum = 0
export default class PolylineMaterialPropery{
    constructor(color = new Cesium.Color(0.7, 0.6, 1.0, 1.0)){
        this.color = color
        this.num = typeNum++
        
        
        this.definitionChanged = new Cesium.Event()

        Cesium.Material._materialCache.addMaterial('PolylineMaterial'+ this.num, {
            fabric: {
                type: 'PolylineMaterial'+this.num,
                uniforms: {
                    uTime: 0,
                    color: this.color
                },
                source: `
                    czm_material czm_getMaterial(czm_materialInput materialInput)
                    {
                        czm_material material = czm_getDefaultMaterial(materialInput);
                        vec2 st = materialInput.st;
                        float time = fract(czm_frameNumber / (60.0*10.0));
                        // time = time * (1.0 + 0.1);
                        float alpha = 0.0;
                        alpha = smoothstep(time-0.1, time,st.s) * step(-time, -st.s);
                        alpha+=0.1;
                        material.diffuse = color.rgb;
                        material.alpha = alpha; // t从右到左，s从下到上，透明到不透明
                        return material;
                    }
                `
            }
        })
        this.params = {
            uTime: 0
        }
    }
    getType() {
        return 'PolylineMaterial' + this.num
    }
    getValue(time, reuslt) {
        reuslt.uTime = this.params.uTime
        return reuslt
    }
    equals(other) {
        return (other instanceof PolylineMaterialPropery && this.color === other.color)
    }
}